package com.zxl.designpattern.structure.proxy;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author zxl
 * @version 1.0
 * @description CGLIB代理处理类，代理实际执行的方法
 * @date 2025/6/1 14:42
 */
public class CarPurchaseInterceptor implements MethodInterceptor {

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        preService();
        Object o1 = methodProxy.invokeSuper(o, objects);
        afterService();
        return o1;
    }

    /**
     * 售前服务
     */
    private void preService(){
        System.out.println("买前服务：介绍车型优惠信息");
    }

    /**
     * 购车后服务
     */
    private void afterService(){
        System.out.println("买后服务：协助办理保险和上牌");
    }


}
